import tensorflow as tf
import numpy as np
from supervised_lenet import inference
from tensorflow.contrib.learn.python.learn.datasets.mnist import read_data_sets
mnist=read_data_sets("MNIST_data/",one_hot=True)

#加载方法1：
image = tf.placeholder(tf.float32,[None,784],name='input_x')
y_ = tf.placeholder(tf.float32,[None,10],name='input_y')
keep_prob = tf.placeholder(tf.float32,name='prob')
loss,logits = inference(image,y_,keep_prob)
# logits = vgg16(image,keep_prob,train_flag)
saver = tf.train.Saver()

with tf.name_scope("accuracy"):
    correct_prediction = tf.equal(tf.argmax(logits, 1), tf.argmax(y_, 1))
    accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

config = tf.ConfigProto(gpu_options=tf.GPUOptions(allow_growth=True))
with tf.Session(config=config) as sess:
    saver.restore(sess,tf.train.latest_checkpoint('./supervised_model'))
    print("finish loading model!")

    # images = test_x[10].reshape(1,32,32,3)
    # label = sess.run(logits,feed_dict={image:images,keep_prob:1.0,train_flag:False})
    # print(np.argmax(label))
    # print(np.argmax(test_y[10]))
    per_dataset = np.load("./target_4_supervised_lenet.npy")
    label = mnist.test.labels[0:1000]
    acc = sess.run(accuracy,feed_dict={image:per_dataset,y_:label,keep_prob:1.0})
    print(str(acc))

